﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HotelCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomNumberController : ControllerBase
    {
        public RoomNumberBLL RoomNumberBLL { get; }

        public RoomNumberController(RoomNumberBLL roomNumberBLL)
        {
            RoomNumberBLL = roomNumberBLL;
        }
        [HttpPost]
        /// <summary>
        /// 添加房号
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult RoomNumberAdd(RoomNumberModel info)
        {
            try
            {
                int res= RoomNumberBLL.RoomNumberAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 房号显示分页
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="totalPage"></param>
        /// <param name="Pageindex"></param>
        /// <param name="Pagesize"></param>
        /// <returns></returns>
        public IActionResult GetRoomNumberList( int Pageindex = 1, int Pagesize = 2)
        {
            try
            {
                int totalCount = 0;
                int totalPage = 0;
                var list= RoomNumberBLL.GetRoomNumberList(out totalCount, out totalPage, Pageindex, Pagesize);
                return Ok(new
                {
                    list= list,
                    totalCount=totalCount,
                    totalPage=totalPage
                });
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 房号Id查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult RoomNumberId(int id)
        {
            try
            {
               var list= RoomNumberBLL.RoomNumberId(id);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult RoomNumberDel(int id)
        {
            try
            {
                 int res= RoomNumberBLL.RoomNumberDel(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 房型修改
        /// </summary>
        /// <param name="roomType"></param>
        /// <returns></returns>
        public IActionResult RoomNumberUpdate(RoomNumberModel info)
        {
            try
            {
               int res= RoomNumberBLL.RoomNumberUpdate(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public IActionResult RoomNumberDelAll(string ids)
        {
            try
            {
                int res=RoomNumberBLL.RoomNumberDelAll(ids);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 批量上架下架
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IActionResult RoomNumberUptAll(string ids, int state)
        {
            try
            {
                int res=RoomNumberBLL.RoomNumberUptAll(ids, state);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
